<?php

include '../connectBDD.php';
if (isset($_GET['id_event']) && isset($_GET['id_dj'])) {
    $id_event = $_GET['id_event'];
    $id_dj = $_GET['id_dj'];
    $query = "insert into event_dj (id_event,id_dj) values ('$id_event','$id_dj')";
    mysql_query($query) or die(mysql_error());

    $result = mysql_query("SELECT * FROM dj WHERE id_dj NOT IN (SELECT id_dj FROM event_dj where id_event=" . $id_event . ")");
    $nb_res = mysql_num_rows($result);
    if ($nb_res > 0) {
        echo "<div class='associationDJ'>
                          <span id='modifierInfo'>
                            <a id='modifDJ' href=\"javascript:associerDJ()\">Associer un DJ à l'évènement</a>
                            <a id='cacherDJ' href=\"javascript:cacher('DJ')\">Cacher</a>
                          </span>
                          <div id='formDJ'>
                                    <form action='' method='post'>
                                    <input name='idEvent' id='idEvent' value='".$id_event."' type='text' style='display:none'/>
                                    <select name='DJ' id='inputDJ'>";
        while ($rows = mysql_fetch_assoc($result)) {
            echo "<option value=" . $rows['id_dj'] . ">" . $rows['pseudo_dj'] . "</option>";
        }
        echo "</select><br/>
                                        <input type='submit' value='enregistrer' name='bouton'/>
                                    </form>
                            </div>
                          </div>
                         ";
    }
    echo "<div><a href=javascript:ouvrirFenetre('creationDJ.php')>Creer un nouveau DJ</a></div>";
    $result = mysql_query("SELECT D.id_dj, D.pseudo_dj FROM dj D INNER JOIN event_dj ED ON D.id_dj = ED.id_dj where ED.id_event = " . $id_event);
    $nb_res = mysql_num_rows($result);
    if ($nb_res > 0) {
        echo "<div style='color:green'>" . $nb_res . " DJ(s) prévus pour cet évènement</div>";
        echo "<div class='djs'>";
        while ($rows = mysql_fetch_assoc($result)) {
            echo "<div id='dj'>
                   ". $rows['pseudo_dj'] . "
                    <div style='float:right'>
                        <a class='croix_ferm' href=\"javascript:retirerDJEvent('" . $rows['id_dj'] . "','" . $id_event . "')\"><img src='../images/Close-32.png' height='15px' width='15px'/></a>
                    </div>
                 </div>";
        }
        echo "</div>";
    } else {
        echo "Aucun DJ n'est prévu pour cet évènement";
    }
    echo "</div>";
}
?>
